<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<title>用户登录</title>
	<link href="__STATIC__/css/common.css" rel="stylesheet">
	<link rel="stylesheet" href="__STATIC__/css/index.css">
</head>

<body ms-controller="view">
	<div class="login-main">
		<div class="form-box">
			<select class="login-item" style="height:30px;" ms-duplex="userName">
				<option value="">请选择用户名</option>
				<option ms-repeat-el="userList" ms-attr-value="el.userName">(|el.userName|)</option>
			</select>
			<input type="password" class="login-item" placeholder="密码" style="height:30px;" ms-duplex="userPwd" />
			<button id="submit"
				style="width:100px;height:40px;background-color:#44B549;color:white;border:1px solid #44B549;border-radius:5px;margin-top:30px;"
				ms-click="signin">登 录</button>
		</div>
	</div>
	<script src="__STATIC__/js/jquery.min.js"></script>
	<script src="__STATIC__/js/layer/layer.js"></script>
	<script src="__STATIC__/js/avalon.js"></script>
	<script src="__STATIC__/js/common.js"></script>
	<script src="__STATIC__/js/jQuery.md5.js"></script>
	<script src="__STATIC__/js/jquery.cookie.min.js"></script>
	<script src="__STATIC__/js/logic.js"></script>
	<script src="__STATIC__/js/validator.js"></script>
	<script>
		jQuery(document).ready(function () {
			avalon.config({
				interpolate: ["(|", "|)"]
			});

			var vm = avalon.define({
				$id: 'view',
				houseId: '',
				userName: '',
				userPwd: '',
				userList: [],
				error: false,
				msg: '',
				load: function () {
					console.log(logic_house);
					TX.msg('正在加载用户列表,请稍后...', { time: 20000 });
					$.post(logic_urls.getAllUserList, {},
						function (data) {
							var json = TX.toJson(data);
							if (json.status == 1) {
								layer.closeAll();
								vm.userList = json.data;
								avalon.scan();
							} else {
								TX.msg('加载用户列表失败,请刷新后再试!', { time: 5000 });
							}
						}
					)
					avalon.scan();
				},
				signin: function () {
					var pd = {
						userName: vm.userName,
						userPwd: $.md5(vm.userPwd + $.md5(vm.userPwd))
					};
					vm.preCheck();
					if (vm.error) {
						TX.msg(vm.msg, { icon: 2 });
						return;
					}
					console.log(pd);
					console.log(logic_urls.adminLogin);
					$.post(logic_urls.adminLogin, pd,
						function (data) {
							var json = TX.toJson(data);
							console.log(json);
							if (json.status == 1) {
								json.data.is_sign_in = true;
								logic_user.onSignin(json.data);
								window.location.href = "{:Url('admin/index/index')}";
							} else {
								TX.msg(json.msg, { icon: 1, time: 2000 });
							}
						}
					);
				},
				preCheck: function () {
					vm.error = false;
					vm.msg = validator.checkText(vm.userName, 1, 20, '用户名');
					if (vm.msg != '') {
						vm.error = true;
						return;
					}
					vm.msg = validator.checkPassword(vm.userPwd, '密码');
					if (vm.msg != "") {
						vm.error = true;
						return;
					}
				}
			});
			vm.load();

			$('body').keypress(function (e) {
				if (e.which == 13) {
					vm.signin();
				}
			});
		});



	</script>
	<!--[if lt IE 9]>
	    <script src="__STATIC__/js/respond.js"></script>
	    <script src="__STATIC__/js/html5shiv.js"></script>
	    <script src="__STATIC__/js/placeholder-IE-fixes.js"></script>
	<![endif]-->
</body>

</html>